package parttern.expression;

public class TerminalExpression implements Expression {

    private String data;

    public TerminalExpression(String data) {
        this.data = data;
    }

    @Override
    public boolean interrupt(String context) {
        return context.contains(data);
    }


    ///test
    public static void main(String[] args) {

        Expression zhangsan = new TerminalExpression("zhangsan");
        Expression lisi = new TerminalExpression("lisi");
        OrExpression orExpression = new OrExpression(zhangsan, lisi);

        Expression xiaofang = new TerminalExpression("xiaofang");
        Expression married = new TerminalExpression("married");
        AndExpression andExpression = new AndExpression(xiaofang, married);

        System.out.println(orExpression.interrupt("lisi"));
        System.out.println(orExpression.interrupt("wanger"));

        System.out.println(andExpression.interrupt("married xiaofang"));
    }
}
